/*t062wrAbzsHyGvc+J5WsZGfSf8HfbFTTE9NsNT/une6jp5RsH2IrbRBQMXT0ZdDD*/
/*
 * @Author: xiahui 
 * @PageInfo: 表体编辑后事件 
 * @Date: 2019-01-14 14:31:50 
 * @Last Modified by: zhr
 * @Last Modified time: 2021-09-08 22:44:15
 */
import { AREA, PAGECODE, URL, FIELDS, CARDTABLEAREAIDS, FREEFIELD } from '../../constance';
import { ajax } from 'nc-lightapp-front';
import { showWarningInfo } from '../../../../../scmpub/scmpub/pub/tool/messageUtil';
import {
	createExtBodyAfterEventData,
	processExtBillCardBodyEditResult
} from '../../../../../scmpub/scmpub/pub/tool/afterEditUtil';
import { marAsstUtils } from '../../../../../scmpub/scmpub/pub/tool';
import { processCardTableAutoAddRow } from '../../../../../scmpub/scmpub/pub/tool/autoAddRowUtil';

export default function(props, moduleId, key, value, rows, index, record) {
	let fixAssts = [ 'casscustvid', 'casscustid', 'cprojectid', 'cproductorid', 'cvendorvid', 'cvendorid' ];
	if (
		FIELDS.delivdate == key ||
		FIELDS.pk_material == key ||
		FIELDS.pk_marbasclass == key ||
		FIELDS.vqtunitrate == key ||
		FIELDS.vchangerate == key ||
		FIELDS.castunitid == key ||
		FIELDS.cqtunitid == key ||
		FIELDS.csendcountryid == key ||
		FIELDS.crececountryid == key ||
		FIELDS.ctaxcountryid == key ||
		FIELDS.ctaxcodeid == key ||
		FIELDS.pk_financeorg_v == key ||
		FIELDS.pk_arrvstock_v == key ||
		FIELDS.outaccountdate == key ||
		FIELDS.paymentday == key ||
		FIELDS.checkdata == key ||
		FIELDS.effectmonth == key ||
		FIELDS.effectaddmonth == key ||
		FIELDS.vtermcode == key ||
		// 需单价金额联动字段
		FIELDS.nastnum == key ||
		FIELDS.vchangerate == key ||
		FIELDS.nnum == key ||
		FIELDS.nqtorigprice == key ||
		FIELDS.nqtorigtaxprice == key ||
		FIELDS.norigprice == key ||
		FIELDS.norigtaxprice == key ||
		FIELDS.ngprice == key ||
		FIELDS.ngtaxprice == key ||
		FIELDS.nqtunitnum == key ||
		FIELDS.ntaxrate == key ||
		FIELDS.ftaxtypeflag == key ||
		FIELDS.norigtaxmny == key ||
		FIELDS.nmny == key ||
		FIELDS.ntax == key ||
		FIELDS.ntaxmny == key ||
		FIELDS.nnosubtaxrate == key ||
		FIELDS.nnosubtax == key ||
		FIELDS.ncaltaxmny == key ||
		FIELDS.nqtprice == key ||
		FIELDS.nqttaxprice == key
	) {
		// 新旧相同，不触发
		let isContinue = false;
		for (let j = 0; j < rows.length; j++) {
			let newvalue = rows[j].newvalue.value == '' ? null : rows[j].newvalue.value;
			let oldvalue = rows[j].oldvalue.value == '' ? null : rows[j].oldvalue.value;
			if (newvalue != oldvalue) {
				isContinue = true;
				break;
			}
		}
		if (!isContinue) {
			return;
		}

		let data = createExtBodyAfterEventData(
			props,
			PAGECODE.cardPagecode,
			AREA.cardFormId,
			CARDTABLEAREAIDS,
			moduleId,
			key,
			rows,
			index,
			{}
		);

		ajax({
			url: URL.bodyAfterEdit,
			data: data,
			async: false,
			success: (res) => {
				if (res.success && res.data) {
					if (res.data.userObject.error) {
						showWarningInfo(null, res.data.userObject.error);
					}
					processExtBillCardBodyEditResult(props, moduleId, res.data);
				}
			}
		});
	} else if (key.indexOf('vfree') == 0 || fixAssts.includes(key)) {
		marAsstUtils.afterEdit.call(
			this,
			props,
			null,
			PAGECODE.cardPagecode,
			moduleId,
			key,
			FIELDS.pk_material,
			record,
			index,
			FREEFIELD
		);
	}
	let defaultVal = {};
	if (moduleId == AREA.cardPayId) {
		defaultVal = {
			[FIELDS.showorder]: { value: props.cardTable.getNumberOfRows(moduleId) + 1 + '' },
			vchangerate: { display: '1/1', value: '1/1' },
			vqtunitrate: { display: '1/1', value: '1/1' }
		};
	} else {
		defaultVal = {
			vchangerate: { display: '1/1', value: '1/1' },
			vqtunitrate: { display: '1/1', value: '1/1' }
		};
	}

	processCardTableAutoAddRow(props, moduleId, index, {
		isMuli: rows.length > 1 ? true : false,
		hasCrownoField: moduleId == AREA.cardTableId,
		crownoField: null,
		defaultValue: defaultVal
	});
}

/*t062wrAbzsHyGvc+J5WsZGfSf8HfbFTTE9NsNT/une6jp5RsH2IrbRBQMXT0ZdDD*/